package com.wanglibao.woodtrade.woodtrade;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.facebook.drawee.view.SimpleDraweeView;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

public class ItemBuyActivityAdapter extends BaseAdapter {

    private List<String> mList = new ArrayList<String>();

    private Context context;
    private LayoutInflater layoutInflater;

    public ItemBuyActivityAdapter(Context context,List<String> list) {
        this.context = context;
        this.mList=list;
        this.layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public String getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.item_buy_activity, null);
            convertView.setTag(new ViewHolder(convertView));
        }
        initializeViews((String)getItem(position), (ViewHolder) convertView.getTag());
        return convertView;
    }

    private void initializeViews(String object, ViewHolder holder) {
        //TODO implement
        holder.sdvItemRv.setImageURI(Uri.parse(object.toString()));
        System.out.println(object.toString());
    }

    static class ViewHolder {
        @Bind(R.id.sdv_item_rv) SimpleDraweeView sdvItemRv;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
